/*******************************************************************************
 * Copyright (c) 2011 TXT e-solutions SpA
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * This work was performed within the IoT_at_Work Project
 * and partially funded by the European Commission's
 * 7th Framework Programme under the research area ICT-2009.1.3
 * Internet of Things and enterprise environments.
 *
 *
 * Authors:
 *     Cristoforo Seccia (TXT e-solutions SpA)
 *
 * Contributors:
 *      Domenico Rotondi (TXT e-solutions SpA)
 *******************************************************************************/
package it.txt.access.capability.demo.soap.client.sws;

import it.txt.access.capability.demo.schema.CapabilityRequestType;
import it.txt.access.capability.demo.schema.CapabilityResponseType;
import it.txt.access.capability.demo.schema.factory.CapabilityDemoSchemaFactory;
import java.util.logging.Logger;
import javax.xml.transform.dom.DOMSource;
import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.w3c.dom.Element;

/**
 *
 * @author Cristoforo Seccia (TXT e-solutions SpA)
 */
public class RequestClient extends WebServiceGatewaySupport {

    private static final Logger LOGGER = Logger.getLogger(RequestClient.class.getName());

    public RequestClient(WebServiceMessageFactory messageFactory) {
        super(messageFactory);
    }

    public CapabilityResponseType userRequest(CapabilityRequestType crt) throws Exception {
        return (CapabilityResponseType) getWebServiceTemplate().marshalSendAndReceive(crt);
    }

    public CapabilityResponseType userRequest(Element requestElement) throws Exception {
        CapabilityRequestType crt = CapabilityDemoSchemaFactory.getCapabilityRequestFromSource(new DOMSource(requestElement));
        return userRequest(crt);
    }

    /*public static void main(String[] args) throws Exception {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                "it/txt/access/capability/demo/soap/client/sws/applicationContext.xml");
        RequestClient requestClient = applicationContext.getBean("capabilityClient", RequestClient.class);
        ObjectFactory objectFactory = new ObjectFactory();
        CapabilityRequestType requestType = objectFactory.createCapabilityRequestType();
        requestClient.userRequest(requestType);
    }*/
}
